<?php  
class contact extends CI_Controller {
	 function contact()
         {
   parent::__construct();
  
   $this->load->model('contact_model');
   $this->load->helper("url_helper");
     $this->load->model('common_model');
       session_start();

    

       }
	public function index()
	{
		$result=$this->common_model->getKeywords('contactus'); 
		$data['keywords']=$result;
		$this->load->view('contact',$data);
	}

	public function contactus()
	{
		 $fname=$_POST['fname'];
		 $lname=$_POST['lname'];
		 $email=$_POST['email'];

         $contactno="";
		 if($_POST['contactno']){
		 $contactno=$_POST['contactno'];
		 }
		 $comments=$_POST['comments'];
		 $contactresponse=$this->contact_model->insertcontact($fname,$lname,$email,$contactno,$comments);
		  
		$result = $this->sendmail($fname,$lname,$email,$comments,$contactno);
		 if($contactresponse=='1')
		    {
			  
			 $this->session->set_flashdata('contact_response', true);
               redirect('contact');
	        }
		     
		  else
		     {
			 $this->session->set_flashdata('contact_error', TRUE);
               redirect('contact');
		     }
		  
	}
 

 public function sendmail($fname,$lname,$email,$comments,$contactno)
    {
      $currentLocation=MAIN_URL; 
     $admincontactEmail = $currentLocation."email/admincontactEmail.html";
     
    $emailto="ajit@sector36.com";
    $fh1 = fopen($admincontactEmail, 'r');
    $htmladminEmail = fread($fh1, 1000);
    fclose($fh1);
    $htmladminEmail = str_replace("XXFirstNameXX",$fname,$htmladminEmail);
    $htmladminEmail = str_replace("XXLastNameXX",$lname,$htmladminEmail);

	$htmladminEmail = str_replace("XXemailXX",$email,$htmladminEmail);
    $htmladminEmail = str_replace("XXcontactnoXX",$contactno,$htmladminEmail);

	$htmladminEmail = str_replace("XXmessageXX",$comments,$htmladminEmail);

	 
   
$subject = "User Contacted on Javatutions";
 
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: '.$email. "\r\n";

mail($emailto,$subject,$htmladminEmail,$headers);
     

  /*
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.googlemail.com';
        $config['smtp_port'] = '465';
        $config['smtp_user'] ='abcdemo001@gmail.com';
        $config['smtp_pass'] = 'demoaccount';

      

$this->load->library('email',$config);

$this->email->set_newline("\r\n");
 
$this->email->from($email);
$this->email->to("mohitmca2011@gmail.com");
$this->email->subject("Contact regarding Java Tution");
$this->email->message($htmladminEmail);

if($this->email->send())
		{
	echo "Your email send";
		}

else {
show_error($this->email->print_debugger());
	}*/
 }}